package com.jytc.framework.utils;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

/**
 * URL处理类
 * @author chenzhijun
 *
 */
public final class UrlUtils
{
	/**
	 * 获得请求的完整URL
	 * @param request
	 * @return
	 */
	public static String getRequestURL(HttpServletRequest request)
	{
		String url = "";
		url = request.getRequestURI() + "?";
		url += getRequestParam(request);
		return url;
	}

	/**
	 * 获得参数URL
	 * @param request
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static String getRequestParam(HttpServletRequest request)
	{
		String url = "";
		Enumeration param = request.getParameterNames();//得到任何参数名

		if (request.getParameter("method") != null)
		{
			url += "method=" + request.getParameter("method") + "&";
		}

		while (param.hasMoreElements())
		{
			String pname = param.nextElement().toString();
			if (!pname.equalsIgnoreCase("method"))
				url += pname + "=" + request.getParameter(pname) + "&";
		}
		if (url.endsWith("&"))
		{
			url = url.substring(0, url.lastIndexOf("&"));
		}
		return url;
	}
}
